﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using MvcEngine.Blog.Models.Entities;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Core.Utils;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Core.Helpers;
using MvcEngine.Mvc.ModelBinders;
using MvcEngine.Core.Base;
using MvcEngine.Blog.Models;

namespace MvcEngine.Blog.ModelBinders
{
    public class OverviewContentModelBinder : ModelBinderBase
    {
        protected int postCount = 4;

        public override object Bind(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;
            OverviewPageContent content = IoC.Resolve<OverviewPageContent>();
            //Add everything to ModelState
            var modelState = controllerContext.Controller.ViewData.ModelState;

            content.PostCount = request.Form.Get("PostCount").ToInt(postCount);

            Validate(content, controllerContext);
            return content;
        }
    }
}
